use $data\edex_data_analytic, clear

capture drop bytthdeg cbytrace* Ttracediff
#delimit;

local prodcont1 inc2 inc3 inc4 highincome;
local prodcont2 cbyrace1-cbyrace5;
local prodcont3 f1rgp9;
local prodcont4 inc2 inc3 inc4 highincome cbyrace1 cbyrace2 cbyrace3 cbyrace4 cbyrace5 f1rgp9 gend; 
local prodcont5 inc2 inc3 inc4 highincome cbyrace1 cbyrace2 cbyrace3 cbyrace4 cbyrace5 f1rgp9 gend bytthdeg cbytrace1-cbytrace5 Ttracediff;
local prodcont5 inc2 inc3 inc4 highincome cbyrace1 cbyrace2 cbyrace3 cbyrace4 cbyrace5 f1rgp9 gend bytthdeg cbytrace1-cbytrace5;

 
qui eststo clear;
qui eststo: reg T1 `prodcont1' i.sch_id if sample, cluster(sch_id); estadd scalar nst=round(e(N),10);
estadd local sfe "Yes";
qui eststo: reg T1 `prodcont2' i.sch_id  if sample, cluster(sch_id); estadd scalar nst=round(e(N),10);
estadd local sfe "Yes";
qui eststo: reg T1 `prodcont3' i.sch_id  if sample, cluster(sch_id); estadd scalar nst=round(e(N),10);
estadd local sfe "Yes";
qui eststo: reg T1 `prodcont4' i.sch_id  if sample, cluster(sch_id); estadd scalar nst=round(e(N),10);
estadd local sfe "Yes";

gen bytthdeg = bytehdeg;
gen cbytrace1 = cbyerace1; 
gen cbytrace2 = cbyerace2; 
gen cbytrace3 = cbyerace3; 
gen cbytrace4 = cbyerace4; 
gen cbytrace5 = cbyerace5;


qui eststo: reg T1 `prodcont5' i.sch_id  if sample, cluster(sch_id); estadd scalar nst=round(e(N),10);
estadd local sfe "Yes";
qui eststo: reg T2 `prodcont1' i.sch_id  if sample, cluster(sch_id); estadd scalar nst=round(e(N),10);
estadd local sfe "Yes";
qui eststo: reg T2 `prodcont2' i.sch_id  if sample, cluster(sch_id); estadd scalar nst=round(e(N),10);
estadd local sfe "Yes";
qui eststo: reg T2 `prodcont3' i.sch_id  if sample, cluster(sch_id); estadd scalar nst=round(e(N),10);
estadd local sfe "Yes";
qui eststo: reg T2 `prodcont4' i.sch_id  if sample, cluster(sch_id); estadd scalar nst=round(e(N),10);
estadd local sfe "Yes";
replace bytthdeg = bytmhdeg;
replace cbytrace1 = cbymrace1; 
replace cbytrace2 = cbymrace2; 
replace cbytrace3 = cbymrace3; 
replace cbytrace4 = cbymrace4; 
replace cbytrace5 = cbymrace5;
qui eststo: reg T2 `prodcont5' i.sch_id  if sample, cluster(sch_id); estadd scalar nst=round(e(N),10);
estadd local sfe "Yes";
esttab using $tables\table_s5.tex, append keep(inc2 inc3 inc4 highincome cbyrace1 cbyrace2 cbyrace3 cbyrace4 cbyrace5 f1rgp9) label collabels(none) nomtitles
mgroups("ELA Teacher Exp." "Math Teacher Exp.", pattern(1 0 0 0 0 1 0 0 0 0) 
prefix(\multicolumn{@span}{c}{) suffix(}) span) 
cells(b(fmt(2) star) se(fmt(2) par)) 
starlevels(* 0.10 ** 0.05 *** 0.01) noobs 
stats(sfe nst r2 r2_a, fmt( 0 0 2 2)
 labels("School FE" "Observations" " $ R^2 $ " "Adjusted $ R^2 $")) 
 title("Teacher Expectations Production Function, School FE" \label{tab:prod});
